package ZorkObjects;

import java.util.ArrayList;
import java.util.HashMap;

public abstract class ZorkObject
{
    protected String name;
    private String status;
    private String description;
    private ArrayList<Trigger> triggers;

    public ZorkObject() {}

    public ZorkObject(HashMap configMap)
    {
        name = (String)configMap.get("name");
        status = (String)configMap.remove("status");
        description = (String)configMap.remove("description");

        triggers = new ArrayList<Trigger>();
        Object o = configMap.remove("trigger");

        if(o instanceof ArrayList)
        {
            for(HashMap h : (ArrayList<HashMap>)o)
            {
                triggers.add(new Trigger(h));
            }
        }
        else if(o instanceof HashMap)
        {
            triggers.add(new Trigger((HashMap)o));
        }
        else 
        {

            if(o != null) {
                System.out.println("this should never happen");
                System.out.println(o.getClass());
            }
        }
    }

	public void setStatus(String newStatus) {
		status = newStatus;
	}

	public String getStatus() {
		return status;
	}

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

	public ArrayList<Trigger> getTriggers() {
		return triggers;
	}

    public String toString()
    {
        String base = "";

        if(name != null && name != "") {
            base += String.format("name=%s\n", name);
        }
        if(status != null && status != "") {
            base += String.format("status=%s\n", status);
        }
        if(description != null && description != "") {
            base += String.format("description=%s\n", description);
        }
        if(triggers.size() > 0) {
            base += "triggers = {\n";

            for(Trigger t : triggers) {
                base += String.format("trigger=%s\n", t.toString());
            }
            base += "}\n";
        }

        return base;
    }
}

